package com.sky.mapper;

import com.sky.entity.AddressBootEntity;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface AddressBootMapper {


    @Insert("insert into address_book (user_id,consignee,sex,phone,province_code,province_name,city_code,city_name,district_code,district_name,detail,label,is_default) values " +
            "(#{userId},#{consignee},#{sex},#{phone},#{provinceCode},#{provinceName},#{cityCode},#{cityName},#{districtCode},#{districtName},#{detail},#{label},#{isDefault})")
    void add(AddressBootEntity entity);


    @Select("select * from address_book where user_id = #{userId}")
    List<AddressBootEntity> getByUserId(Long userId);

    @Select("select * from address_book where user_id = #{userId} and is_default = 0")
    AddressBootEntity getDefault(Long userId);

    void update(AddressBootEntity entity);

    @Delete("delete from address_book where id =#{id}")
    void delete(Long id);

    @Select("select * from address_book where id =#{id}")
    AddressBootEntity getById(Long id);

    void cleanDefault(@Param("list") List<Long> ids);
}
